<?php
/**
 * Created by PhpStorm.
 * User: Keter
 * Date: 2016/8/3
 * Time: 16:55
 */
class DiamondLogQueen extends StatsLogBase
{
    public $queenName = 'diamondLog';
    public $baseTableName = 'log_diamond';

    /**
     * 推入队列
     * @param $data
     * @return bool
     * @throws Exception
     */
    public function push($data)
    {
        return parent::pushQueen($data,'push_diamond_log_error', 'user_stats');
    }

    /**
     * 保存到数据库
     * @param $data
     * @return array
     */
    public function saveLog($data)
    {
        /**
         * 保存数据
         */
        $data = [
            'uid'        => $data['uid'],
            'type'       =>  (integer)$data['type'],
            'payType'    =>  (integer)$data['payType'],
            'actType'    => 0,
            'gameType'   => (int)$data['gameType'],
            'platform'   => (integer)$data['platform'],
            'channelID'  => (integer)$data['channelID'],
            'version'    => empty($data['version'])?'':$data['version'],
            'nickname'   => empty($data['nickname'])?'':$data['nickname'],
            'diamond'    => (integer)$data['diamond'],
            'oldDiamond' => (integer)$data['oldDiamond'],
            'newDiamond' => (integer)$data['newDiamond'],
            '`desc`'     => empty($data['desc'])?'':$data['desc'],
            'createTime' => $data['createTime'],
        ];

        $result = $this->mysql('logs')->insert($this->tableName, $data, true);
        if (!$result) {
            $this->e('save_error', $this->mysql('logs')->error());
            $this->e('钻石日志保存失败', $data);
            return [];
        }

        return $data;
    }
}